package dao

import (
	"fmt"
	"hft/Http/Models/request"

	"gorm.io/gorm"
)

type HelpActive struct{}

func (h *HelpActive) JustGroup(groupId int, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if groupId == 0 {
			return db
		} else {
			return db.Where("active_group = ?", groupId)
		}
	}
}

func (h *HelpActive) JustName(name string, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Where("name LIKE ?", fmt.Sprintf("%%%v%%", name))
	}
}

func (h *HelpActive) GetActiveList(accountId int, paginate *request.HelpActivePage, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Scopes(h.JustGroup(paginate.ActiveGroup, db)).Scopes(h.JustName(paginate.Name, db)).Where("account_id = ?", accountId).Scopes(Paginate(Page(paginate.Page), db))
	}
}

var HelpActiveDao = new(HelpActive)
